
import random

class Route:
    """
    A connection between 2 towns
    """
    
    def __init__(self, cost = 0):
        """
        cost - The cost of using this route.
        """
        self._cost = cost
        self._actor_costs = {}
    
    def get_cost(self):
        """
        Returns the cost of 
        """
        return self._cost
    
    
    def set_cost(self, cost):
        """
        Sets the cost of this route.
        """
        self._cost = cost
        
    def rand_cost(self, min = 0, max = 100):
        """
        Randomizes the cost of this route
        min - The minimum cost that this route can have
        max - The maximum cost that this route can have
        """
        self._cost = int(random.uniform(min, max))
    
    def rand_cost_poly(self, exp = 1, min = 0, max = 100):
        """
        Randomizes the cost of this route, raising the random values to the
        exponent 'exp' to produce a more bottom heavy distribution.
        exp - The exponent to raise all values to.
        min - The minimum random variable value
        max - The maximum random variable value
        """
        self._cost = int(random.uniform(min, max)**exp)
        
    def actor_set_cost(self, actor, cost):
        """
        Sets the expected cost of this route for a given actor. The actor should
        be an object with the default user type __hash__ function, using
        id(actor) as the hash value
        actor - The actor with the expected cost
        cost - The cost that this actor expects
        """
        
        self._actor_costs[actor] = cost
        
    def actor_get_cost(self, actor):
        """
        Gets the expected cost of this route for a given actor.  If the actor
        has not declared their expected cost of this route, returns None
        actor - The actor of the expected cost
        """
        if not actor in self._actor_costs:
            return None
        return self._actor_costs[actor]
       
    
    